package com.example.myapplication.ArrayAdapterInclude;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;
import com.example.myapplication.R;

public class CheckedViewArrayAdapter extends ArrayAdapter<String> {
  public CheckedViewArrayAdapter(Context context, String[] data) {
    super(context, R.layout.listitem_view,data);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView= LayoutInflater.from((getContext())).inflate(R.layout.checkeditemlayout,parent,false);
    }
    CheckedTextView textView=(CheckedTextView) convertView.findViewById(R.id.checkedTextView);
    textView.setText(getItem(position));
    textView.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        textView.toggle();
      }
    });
    return convertView;
  }
}
